package com.easy.web.api;

import com.easy.common.core.R;
import com.easy.common.utils.mail.MailUtils;
import com.easy.common.mq.MessageRocketProducer;
import com.easy.common.utils.mail.SendMailUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 验证码api
 *
 * @author RuoYu
 * @date 2022/11/17
 */
@RestController
@RequestMapping("/login/check/")
@Api(tags = "验证码api")
public class VerificationCodeApi {
    @Autowired
    private SendMailUtils sendMailUtils;

    @Autowired
    private MailUtils mailUtils;

    /**
     * 发送短信
     * 发送 电话 验证码
     *
     * @param phone 用户登录手机号
     * @return {@link R}<{@link String}>
     */
    @GetMapping("sendSMS")
    @ApiOperation(value = "发送 电话 短信")
    @ApiImplicitParam(name = "phone", value = "用户电话", dataTypeClass = String.class, required = true)
    public R<String> sendSMS(String phone) {
//        sendMailUtils.sendMail(phone, "231334");
        return R.success("短信发送失败");
    }

    @Autowired
    private MessageRocketProducer messageRocketProducer;

    /**
     * 发送 邮件 验证码
     *
     * @param email 用户登录邮箱
     * @return {@link R}<{@link String}>
     */
    @GetMapping("sendEmail")
    @ApiOperation(value = "发送 邮件 验证码")
    @ApiImplicitParam(name = "email", value = "用户邮箱", dataTypeClass = String.class, required = true)
    public R<String> sendEmail(String email) {
        R r = mailUtils.sendMail(email);
        return r;
    }
}
